/*
   Copyright (c) 2019 Shanghai Xuanzi Technology Co. Ltd https://xuanzi.ltd
   XZMindMap is licensed under the Mulan PSL v1.
   You can use this software according to the terms and conditions of the Mulan PSL v1.
   You may obtain a copy of Mulan PSL v1 at:
      http://license.coscl.org.cn/MulanPSL
   THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
   IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
   PURPOSE.
   See the Mulan PSL v1 for more details.

*/

package xuanzi.xzmind.client;
 
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.dom.client.CanvasElement;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.RootPanel;

import xuanzi.commons.graphics.Paint;
import xuanzi.commons.graphics.SVGCanvas;
import xuanzi.openmind.lines.Line;
import xuanzi.openmind.lines.RoundLine;
import xuanzi.openmind.nodes.Node;
import xuanzi.openmind.nodes.Sheet;
import xuanzi.openmind.renders.RenderBuffer;
import xuanzi.openmind.scenes.DefaultScene;
import xuanzi.openmind.scenes.base.EastScene;
import xuanzi.openmind.scenes.base.Scene;
import xuanzi.openmind.scenes.base.WestScene;
import xuanzi.openmind.shapes.Round;
import xuanzi.openmind.themes.Theme;
 

public class XZMind   implements EntryPoint{

	public XZMind() {
		// TODO Auto-generated constructor stub
	}

	CanvasElement ce ;
	
	@Override
	public void onModuleLoad() {
		// TODO Auto-generated method stub
		ce = DOM.createElement("canvas").cast();
		Node root = new Node("DDDDD");
		Scene scene = new EastScene();
		root.setScene(scene);
		root.setShape(new Round());
		root.setLine(new RoundLine());
		for(int i=0;i<5;i++) {
			Node node = root.addNode("这是一个例子例子 "+i);
			for(int x=0;x<3;x++) {
				node.addNode("Node "+x);
			}
		}
		Sheet sheet = new Sheet();
		sheet.setRoot(root);
		
		SVGCanvas canvas = new SVGCanvas() {
			@Override
			public float textWidth(String text, boolean mline, Paint paint) {
				if(text==null)
					return 0; 
				ce.getContext2d().setFont(paint.textSize+"px 微软雅黑");
				return (float) ce.getContext2d().measureText(text).getWidth();
			}
		};
		sheet.setTheme(new Theme()); 
		RenderBuffer.canvas = canvas;
	//	root.requestLayout();
		sheet.layoutChange(true);
		
		canvas.resize(scene.box().width(), scene.box().height());
		sheet.drawPicture(canvas);
		RootPanel.getBodyElement().setInnerHTML(canvas.toString());
	//	Window.alert("DDD");
	}

	public static void main(String[] args) {
		XZMind x = new XZMind();
		x.onModuleLoad();
	}
}
